import { Component, OnInit } from '@angular/core';
import {User} from '../../domain/user'
import {AdministrativeService} from '../../service/administrative.service'
/*

@Author:刘洋

@Date: 2018-12-12

@员工信息管理功能实现

@Last Modified time: 2018-12-16
*/
@Component({
  selector: 'app-administrative-employeeinfo',
  templateUrl: './administrative-employeeinfo.component.html',
  styleUrls: ['./administrative-employeeinfo.component.css']
})
export class AdministrativeEmployeeinfoComponent implements OnInit {

  constructor(private administrativeService:AdministrativeService) { }
  users : User[];
  selectUser:User;
  ngOnInit() {
    this.getUsers();
  }
  getUsers():void{
    this.administrativeService.getUsers()
    .subscribe(users => this.users = users);
  }
  onSelect(user){
    this.selectUser = user;
  }
  updateUser(uuser:User){
    this.administrativeService.updateUser(uuser)
    .subscribe(()=>{alert("修改成功");});
  }
  getUserLike(id:number){
    this.administrativeService.getUserLike(id)
    .subscribe(users => {this.selectUser=null;this.users = users;});
  }
  deleteUser(user:User){
    if (confirm("确定删除" + user.name + "？")) {
      this.administrativeService.deleteUserConfirm(user.id).
      subscribe();
      this.administrativeService.deleteUser(user).
      subscribe(()=>{alert("删除成功");this.selectUser=undefined;this.getUsers();});
    }
  }
}
